import {
  getList as getBaseUserList,
  getLineCodeList,
  getTeamCodeList,
  getEducationList,
  getUserTypeList
} from '@/api/employee/mesUserExtend'

export const baseUserDialog = {
  data () {
    return {
      baseUserDialogVisible: false, //表格弹框隐藏显示
      getBaseUserList, // 获取弹框数据接口
      hasBaseUserFooter: true, // 是否需要底部按钮默认true
      baseUserSearchDialog: {
        inline: true,
        formDesc: {
          userName: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesTeam.userName')
          }
        }
      },
      baseUserDialogColumn: [
        {
          type: 'selection',
          fixed: 'left'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60,
          fixed: 'left'
        },
        {
          prop: 'userCode',
          label: $i18n.t('mesTeam.userCode'),
          minWidth: 120,
          fixed: 'left',
          showOverflowTooltip: true
          // optionProp: {
          //   value: 'value',
          //   label: 'description',
          // },
          // option: async (data) => {
          //   const list = await getUserCodeList()
          //   return list.data.result
          // },
        },
        {
          prop: 'userName',
          label: $i18n.t('mesTeam.userName'),
          minWidth: 130,
          fixed: 'left',
          showOverflowTooltip: true
        },
        {
          prop: 'lineCode',
          label: $i18n.t('mesTeam.lineCode'),
          minWidth: 120,
          showOverflowTooltip: true,
          optionProp: {
            value: 'modelingCode',
            label: 'modelingCode'
          },
          option: async (data) => {
            const params = {
              modelingCode: this.$store.getters.factoryCode,
              level: 5
            }
            const list = await getLineCodeList(params)
            // self.submitProdLineList = list.data.result
            return list.data.result
          }
        },
        {
          prop: 'lineName',
          label: $i18n.t('mesTeam.lineName'),
          minWidth: 140,
          showOverflowTooltip: true
        },
        {
          prop: 'workCellCode',
          label: $i18n.t('mesTeam.workCellCode'),
          minWidth: 120,
          showOverflowTooltip: true,
          optionProp: {
            value: 'modelingCode',
            label: 'modelingCode'
          }
          // option: async (data) => {
          //
          //   const list = await getWorkCellCodeList()
          //   self.submitWorkCellList = list.data.result
          //   console.log("<<<<<<  "+self.submitWorkCellList.length)
          //   return list.data.result
          // },
        },
        {
          prop: 'workCellName',
          label: $i18n.t('mesTeam.workCellName'),
          minWidth: 130,
          showOverflowTooltip: true
        },
        {
          prop: 'teamCode',
          label: $i18n.t('mesTeam.team'),
          minWidth: 120,
          showOverflowTooltip: true,
          optionProp: {
            value: 'teamCode',
            label: 'teamName'
          },
          option: async (data) => {
            const list = await getTeamCodeList()
            return list.data.result
          }
        },

        {
          prop: 'education',
          label: $i18n.t('mesTeam.education'),
          showOverflowTooltip: true,
          optionProp: {
            value: 'value',
            label: 'description'
          },
          minWidth: 130,
          option: async (data) => {
            const list = await getEducationList()
            return list.data.result
          }
        },
        {
          prop: 'birthday',
          label: $i18n.t('mesTeam.birthday'),
          minWidth: '160',
          showOverflowTooltip: true
        },
        {
          prop: 'timeEntry',
          label: $i18n.t('mesTeam.timeEntry'),
          minWidth: '170',
          showOverflowTooltip: true
        },
        {
          prop: 'departureTime',
          label: $i18n.t('mesTeam.departureTime'),
          minWidth: '170',
          showOverflowTooltip: true
        },
        {
          prop: 'userType',
          label: $i18n.t('mesTeam.userType'),
          minWidth: 120,
          showOverflowTooltip: true,
          optionProp: {
            value: 'value',
            label: 'description'
          },
          option: async (data) => {
            const list = await getUserTypeList()
            return list.data.result
          }
        },
        {
          prop: 'postCode',
          label: $i18n.t('mesTeam.postCode'),
          minWidth: 120,
          showOverflowTooltip: true
          // optionProp: {
          //   value: "value",
          //   label: "description",
          // },
          // option: async (data) => {
          //   const list = await getPostCodeList();
          //   return list.data.result;
          // },
        },
        {
          prop: 'postName',
          label: $i18n.t('mesTeam.postName'),
          minWidth: 120,
          showOverflowTooltip: true
        },
        {
          prop: 'email',
          label: $i18n.t('mesTeam.email'),
          minWidth: 200,
          showOverflowTooltip: true
        },
        {
          prop: 'phone',
          label: $i18n.t('mesTeam.phone'),
          minWidth: 160,
          showOverflowTooltip: true
        },
      ]
    }
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectBaseUser (data) {
      // 调试完成记得删除控制台打印
      //console.log("选中数据", data[0]);
      // 这里可以自定义返回字段信息
      // 第一个入参为当前表单绑定的对象，第二个入参为要修改的字段名，第三个入参为选中数据中相应信息
      this.$set(this.formDataDialog, 'teamLeaderCode', data[0].userCode)
      this.$set(this.formDataDialog, 'teamLeaderName', data[0].userName)
    }
  }
}
